package com.itao.poi.tl.util;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

/**
 * @author sjt
 * @Date 2024/10/10 8:59
 */
public class ResourceUtil {

    private static URI getURI(){
        try {
            return Objects.requireNonNull(ResourceUtil.class.getClassLoader().getResource("")).toURI();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static String getDocxPath(String fileName) {
        return Paths.get(getURI()) + File.separator + "docx" + File.separator + fileName;
    }

    public static String getDocxOutPath(String fileName) {
        String outPath = Paths.get(getURI()) + File.separator + "out";
        try {
            Path path = Paths.get(outPath);
            if (!Files.exists(path)) {
                Files.createDirectories(path);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return outPath + File.separator  + fileName;
    }

    public static String getImagePath(String fileName) {
        String outPath = Paths.get(getURI()) + File.separator + "image";
        try {
            Path path = Paths.get(outPath);
            if (!Files.exists(path)) {
                Files.createDirectories(path);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return outPath + File.separator  + fileName;
    }

}
